package net.pimpas.transformation.javascript.json.serviceprovider;

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Reader;
import java.io.Writer;

import net.pimpas.core.configuration.exception.ConfigurationException;
import net.pimpas.core.serviceprovider.ServiceProviderAnnotation;
import net.pimpas.core.serviceprovider.instancetype.ServiceProviderInstanceType;
import net.pimpas.transformation.javascript.serviceprovider.JavascriptTransformationServiceProvider;
import net.pimpas.transformation.serviceprovider.exception.TransformationServiceProviderException;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;


@ServiceProviderAnnotation(
		instanceType=ServiceProviderInstanceType.NORMAL,
		serviceProviderType=JavascriptTransformationServiceProvider.class
)
public class JSonJavascriptServiceProviderImpl implements JSonJavascriptServiceProvider {

	public ObjectInputStream createObjectInputStream(Reader arg0) throws TransformationServiceProviderException {
		return null;
	}

	public ObjectOutputStream createObjectOutputStream(Writer arg0) throws TransformationServiceProviderException {
		return null;
	}

	public Object from(JSONObject arg0, Object... arg1) throws TransformationServiceProviderException {
		try {
			return JSONObject.toBean(arg0, (Class) arg1[0]);
		} catch(Exception e) {
			throw new TransformationServiceProviderException(e);
		}
	}

	public JSONObject to(Object arg0, Object... arg1) throws TransformationServiceProviderException {
		try {
			return JSONObject.fromBean(arg0);
		} catch(Exception e) {
			throw new TransformationServiceProviderException(e);
		}
	}

	public void config() throws ConfigurationException {
		
	}

	public JSONArray fromArray(Object[] array) throws TransformationServiceProviderException {
		try {
			return JSONArray.fromArray(array);
		} catch(Exception e) {
			throw new TransformationServiceProviderException(e);
		}
	}

	public Object[] toArray(JSONArray object) throws TransformationServiceProviderException {
		try {
			return JSONArray.toArray(object);
		} catch(Exception e) {
			throw new TransformationServiceProviderException(e);
		}
	}
	
	public boolean isTerminated() {
		return false;
	}
}